using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using TuMama;
using System.Collections;
using System.Threading;
using System.Globalization;

namespace WindowsApplication2
{
    public partial class SaladeEspera : Form
    {
        private Match match;
        bool esp;

        public SaladeEspera()
        {
            this.match = Match.thismatch;
            this.match.ListaJugadoresActualizada += new EventHandler(match_ListaJugadoresActualizada);
            this.match.GameStarted += new EventHandler(match_GameStarted);
            this.match.DoWaiting += new EventHandler(match_DoWaiting);
            InitializeComponent();
        }

        void match_DoWaiting(object sender, EventArgs e)
        {
            this.Enabled = true;
            this.Visible = true;
            this.Focus();
            label4.Text = match.PlayerName;
        }

        void match_GameStarted(object sender, EventArgs e)
        {
            this.match.ListaJugadoresActualizada -= match_ListaJugadoresActualizada;
            this.match.GameStarted -= match_GameStarted;
            this.Hide();
        }

        void match_ListaJugadoresActualizada(object sender, EventArgs e)
        {
            ArrayList temp = match.ListaJugadores;
            listBox1.Items.Clear();
            foreach (Jugador x in temp)
            {
                if (esp)
                    listBox1.Items.Add(x.NombreJugador + " - " + (x.Estado == Jugador.status.ready ? "listo" : "esperando"));
                else
                    listBox1.Items.Add(x.NombreJugador + " - " + (x.Estado == Jugador.status.ready ? "ready" : "not ready"));

            }
        }


        private void SaladeEspera_Load(object sender, EventArgs e)
        {
            this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
            this.MaximizeBox = false;
            if (Thread.CurrentThread.CurrentUICulture.Equals(new CultureInfo("es-MX")))
                esp = true;
            else
                esp = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Mensaje nuevo = new Mensaje(null, Mensaje.tipoObjeto.NULL, Mensaje.message.ready);
            match.SendMessage(nuevo);
            button1.Enabled = false;
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

    }
}